package com.itheima.advantagesup.controller;


import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.YddCateDTO;
import com.itheima.advantagesup.entity.YddCate;
import com.itheima.advantagesup.service.YddCateService;
import com.itheima.advantagesup.vo.CateVO;
import com.itheima.advantagesup.vo.YddCatePageBeanVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/ydd_cate")
public class YddCateController {
    @Autowired
    private YddCateService yddCateService;

    @GetMapping("/all")
    public R all(){
        log.info("获取全部数据");
        List<CateVO> list = yddCateService.all();
        return  R.success(list);
    }

    @GetMapping("/list")
    public R list(String catename, Integer page ,Integer limit){
        log.info("分页查询:{}",catename);
        YddCatePageBeanVO yddCatePageBeanVO = yddCateService.list(catename,page,limit);
        return R.success(yddCatePageBeanVO);
    }

    @PostMapping("/add")
    public R add(@RequestBody YddCateDTO yddCateDTO){
        log.info("添加分类:{}",yddCateDTO);
        yddCateService.add(yddCateDTO);
        return R.success();
    }

    @GetMapping("/del")
    public R delete(String id){
        log.info("删除用户通过id:{}");
        yddCateService.delete(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R getCateById(String id){
        log.info("根据id查询分类:{}",id);
        CateVO cateVO = yddCateService.getCateById(id);
        return R.success(cateVO);
    }

    @PostMapping("/update")
    public R update(@RequestBody YddCateDTO yddCateDTO){
        log.info("修改员工:{}",yddCateDTO);
        yddCateService.update(yddCateDTO);
        return R.success();
    }
}
